import router from './router'
import { userInfo } from '@/apis/Common'
import { Message } from 'element-ui'
import { getRealToken } from '@/utils/util.js'
router.beforeEach(async (to, from, next) => {
  // next()

  const accessObj = getRealToken()
  const frontTokenKey = accessObj?.insightToken

  if (!!frontTokenKey) {
    userInfo().then((res) => {
      if (res.code === 200) {
        next()
      } else {
        next({
          path: '/404'
        })
      }
    })
  } else if (to.path === '/404') {
    next()
  } else {
    next({
      path: '/404'
    })
    Message({
      message: 'token失效，请重新登录！',
      type: 'error',
      duration: 5 * 1000
    })
  }
})
router.afterEach((to) => {
  if (to.meta.title) document.title = to.meta.title
})
